<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>slot-作用域插槽</title>
    <script src="../lib/vue_v2.6.14.js"></script>
  </head>
  <body>
    <div id="app">
      <son-cpn></son-cpn>
      <son-cpn>
        <!-- 需求：获取子组件的 languages -->
        <!-- 以下就是作用域插槽的使用 -->
        <template slot-scope="slot">
          <span>{{ slot.data.join(' - ') }}</span>
        </template>
      </son-cpn>
    </div>

    <template id="cpn">
      <div>
        <slot :data="languages">
          <ul>
            <li v-for="(item, index) in languages" :key="index">{{ item }}</li>
          </ul>
        </slot>
      </div>
    </template>
    <script>
      const vm = new Vue({
        el: '#app',
        components: {
          'son-cpn': {
            template: '#cpn',
            data() {
              return {
                languages: ['Vue', 'React', 'Angular']
              }
            }
          }
        },
        data: {
          message: '你好呀'
        }
      })
    </script>
  </body>
</html>
